'''
Created on 23/05/2011

@author: humberto
'''

'''
Some Global variables for controlling file names
'''
InstalledAppsFile = "/var/lib/dpkg/status"

class Package:
    def __init__(self, name, version, cfg):
        self._name = name
        self._version = version
        self._cfgfile = cfg
    def GetVersion(self):
        return self._version
    def GetName(self):
        return self._name
    
def Parse():
    Packages = []
    TmpName = ''
    TmpVer = ''
    InstalledApps = open(InstalledAppsFile, "r")
    if not InstalledApps:
        return False
    StillSamePackage = False
    for line in InstalledApps:
        if line.find('Package: ') != -1:
            try:
                TmpName = line.split(':')[1].replace('\n','')
            except:
                pass
            StillSamePackage = True
            
        if StillSamePackage and line.find('Version: ') != -1:
            try:
                TmpVer = line.split(':')[1].replace('\n','')
            except:
                pass
            Packages.append(Package(TmpName, TmpVer, None))
            StillSamePackage = False
    return Packages
